package com.shaobufan.museum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaobufan.museum.mapper.MissionMapper;
import com.shaobufan.museum.pojo.entity.Mission;
import com.shaobufan.museum.pojo.request.mission.MissionAddRequest;
import com.shaobufan.museum.service.MissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 17126
 * @description 针对表【mission(任务表)】的数据库操作Service实现
 * @createDate 2024-04-22 12:10:45
 */
@Service
public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission>
        implements MissionService {
    @Resource
    MissionMapper missionMapper;

    /**
     * 添加任务
     *
     * @param missionAddRequest 任务参数
     * @return Boolean
     */
    @Override
    public Boolean addMission(MissionAddRequest missionAddRequest) {
        Mission mission = getMission(missionAddRequest);
        missionMapper.insert(mission);
        return true;
    }

    @Override
    public List<Mission> getMission(Integer departId) {
        QueryWrapper<Mission> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("depart_id", departId);

        return missionMapper.selectList(queryWrapper);
    }

    public Mission getMission(MissionAddRequest missionAddRequest) {
        Mission mission = new Mission();
        mission.setMissionName(missionAddRequest.getMissionName());
        mission.setMissionDetail(missionAddRequest.getMissionDetail());
        mission.setMissionLevel(missionAddRequest.getMissionLevel());
        mission.setDeadline(missionAddRequest.getDeadline());
        mission.setDepartId(missionAddRequest.getDepartId());

        return mission;
    }
}